string(REGEX MATCH "([0-9.]+)$" MOTIONBUILDER_VERSION "${CMAKE_CURRENT_SOURCE_DIR}")
set(MESHSYNC_CLIENT_MOTIONBUILDER "MeshSyncClientMotionBuilder${MOTIONBUILDER_VERSION}")
find_package(MotionBuilder${MOTIONBUILDER_VERSION})
add_definitions(-DMOTIONBUILDER_VERSION=${MOTIONBUILDER_VERSION})

file(GLOB sources *.cpp *.h)
add_library(${MESHSYNC_CLIENT_MOTIONBUILDER} SHARED ${sources})
add_dependencies(${MESHSYNC_CLIENT_MOTIONBUILDER} MeshUtils MeshSync)
target_include_directories(${MESHSYNC_CLIENT_MOTIONBUILDER} PUBLIC "${CMAKE_SOURCE_DIR}" "${MOTIONBUILDER${MOTIONBUILDER_VERSION}_INCLUDE_DIR}")
target_link_libraries(${MESHSYNC_CLIENT_MOTIONBUILDER} MeshSync MeshUtils ${Poco_LIBRARIES} ${MOTIONBUILDER${MOTIONBUILDER_VERSION}_LIBRARIES})
if(ENABLE_ZSTD)
    target_link_libraries(${MESHSYNC_CLIENT_MOTIONBUILDER} ${ZSTD_LIBRARY})
endif()
if(LINUX)
    target_link_libraries(${MESHSYNC_CLIENT_MOTIONBUILDER} pthread "-Wl,--no-undefined")
elseif(MAC)
    set_target_properties(${MESHSYNC_CLIENT_MOTIONBUILDER} PROPERTIES COMPILE_FLAGS -DOSMac_)
    set_target_properties(${MESHSYNC_CLIENT_MOTIONBUILDER} PROPERTIES SUFFIX ".bundle")
endif()
set_target_properties(${MESHSYNC_CLIENT_MOTIONBUILDER} PROPERTIES PREFIX "")
set_target_properties(${MESHSYNC_CLIENT_MOTIONBUILDER} PROPERTIES OUTPUT_NAME "MeshSyncClientMotionBuilder")

set(DIST_DIR "${CMAKE_INSTALL_PREFIX}/UnityMeshSync_MotionBuilder_${PLATFORM}")
set(CONTENT_DIR "${DIST_DIR}/MotionBuilder${MOTIONBUILDER_VERSION}")

install(TARGETS ${MESHSYNC_CLIENT_MOTIONBUILDER} DESTINATION "${CONTENT_DIR}/")
